package com.csy.bservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.csy.bservice.entity.User;
import com.csy.bservice.feign.BFeginA;
import com.csy.bservice.service.IUserService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xx
 * @since 2025-01-07
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    IUserService userService;

    @Autowired
    BFeginA bFeginA;

    @RequestMapping("/foudsTransfer")
    @GlobalTransactional
    @Transactional
    public String foudsTransfer(){
        //b服务扣减余额，调a服务扣减库存
        userService.update(new User().setBalance(0),
                new UpdateWrapper<User>().eq("username","zhangsan"));
        userService.update(new User().setBalance(200),
                new UpdateWrapper<User>().eq("username","lisi"));
        System.out.println("-------BBBBService");
        bFeginA.deStock();
        return "-----购买成功";
    }
}
